package com.tank.jdk8.stream;

import lombok.extern.slf4j.Slf4j;
import org.junit.Test;

import java.util.ArrayList;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: SuQiEr
 * Date:2017/4/8 0008
 * Time: 上午 10:40
 * To change this template use File | Settings | File Templates.
 */
@Slf4j
public class ForeachTest {

    @Test
    public void testForeach(){

        int size = 10;

        List<Student> list = new ArrayList<Student>(){{
            for (int i = 0; i < size; i++) {
                add(new Student(i+"",i));
            }
        }};
        long startTime = System.currentTimeMillis();
        for (Student stu:list) {
            if(stu.getAge() > size){
                throw new NullPointerException();
            }
        }
        try {
            list.parallelStream().forEach(item ->{
                if(item.getAge() > 5){
                    throw new NullPointerException();
                }
                log.info("item:{}"+item);
            });

        }catch (Exception ex){
            log.error("xxxxxx");
        }

        //System.out.println("used times:{}"+(System.currentTimeMillis()-startTime));
    }
}


